home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / TOPUSER.SCR < prev    next >
Text File  |  1993-02-01  |  10KB  |  250 lines

  1.  
  2. // TOPUSER.SCR  --  Maximus Top User Report Generator  --  Version 1.00
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6.  
  7. // TOPUSER scans the Maximus USER.BBS file, and writes an 'avatar'
  8. // *.BBS file for online display. It lists the top ~15 callers, uploaders
  9. // downloaders, and displays totals. There are no command line parameters,
  10. // edit the following entries to suit your system.
  11.  
  12. char *rfile = "TOPUSER.BBS";                // Path & name of report file
  13. char *ufile = "USER.BBS";                   // Path & name of Maximus user file
  14. //char *ufile = "C:\\BBS\\USER.BBS";        // Path & name of Maximus user file
  15. int rnum=15;                                // Report number
  16.  
  17. // AVAILABLE COLOUR CONSTANTS
  18. // Foreground & Background:
  19. // BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LGREY
  20. // Foreground ONLY:
  21. // DGREY, LBLUE, LGREEN, LCYAN, LRED, LMAGENTA, YELLOW, WHITE
  22.  
  23. char COLOURHEAD = WHITE;                    // Report headline colour
  24. char COLOURHUND = LRED;                     // Report underline colour
  25. char COLOURBOXB = CYAN;                     // Report box colour
  26. char COLOURLABL = LCYAN;                    // Report box label colour
  27. char COLOURLABB = BLUE;                     // Report box label bg colour
  28. char COLOUROPT1 = YELLOW;                   // Highlight colour one
  29. char COLOUROPT2 = LGREEN;                   // Highlight colour two
  30. char COLOUROPT3 = LRED;                     // Highlight colour three
  31. char COLOURDATA = LGREY;                    // Report data colour
  32.  
  33. char *banner = "TOPUSER v1.00";             // Script banner
  34. char *desc = "Top User Reporter";           // Description
  35. char MCLS=0x0C;                             // Avatar 'clear screen'
  36. char MENTER=0x01;                           // Maximus 'press enter'
  37. char MMOREOFF=0x0B;                         // Maximus 'more off'
  38.  
  39. long ctotal=0;                              // Report calls total
  40. long utotal=0;                              // Report uploads total
  41. long dtotal=0;                              // Report dnloads total
  42.  
  43. int cidx[rnum];                             // Top caller array
  44. int uidx[rnum];                             // Top uploader array
  45. int didx[rnum];                             // Top dnloader array
  46.  
  47. long fp;                                    // Report file handle
  48.  
  49. main ()                                     // Main program
  50. {
  51.     printf ("\n%s - %s\n\n",banner,desc);   // Announce
  52.  
  53.     if (!BaseOpenR (ufile)) {
  54.         printf ("ERROR opening user file %s\n",ufile);
  55.         saybibi (); exit ();
  56.     }
  57.  
  58.     if (scanufile ()) writereport ();       // Process the user file
  59.  
  60.     BaseClose ();                           // Close the user base
  61.     saybibi ();                             // Was it good for you too?
  62. }
  63.  
  64. // Collect sort indexes and scan for totals
  65. scanufile ()
  66. {
  67.     int i;
  68.  
  69.     printf ("Collecting the %d top Callers ",rnum);
  70.  
  71.     // Collect calls index
  72.     BaseSort (IDX_CALLS);                   // Sort the base by calls
  73.     for(i=2;i<=rnum+1;i++) {                // For 'rnum' records
  74.         if(i>BaseCount ()) break;           // Abort if out of records
  75.         cidx[i-2]=BaseIdx (i);              // Save the record number
  76.     }
  77.  
  78.     printf ("\nCollecting the %d top Uploaders ",rnum);
  79.  
  80.     // Collect upload index
  81.     BaseSort (IDX_UPLD);                    // Sort the base by uploads
  82.     for(i=2;i<=rnum+1;i++) {                // For 'rnum' records
  83.         if(i>BaseCount ()) break;           // Abort if out of records
  84.         uidx[i-2]=BaseIdx (i);              // Save the record number
  85.     }
  86.  
  87.     printf ("\nCollecting the %d top Dnloaders ",rnum);
  88.  
  89.     // Collect dnload index
  90.     BaseSort (IDX_DNLD);                    // Sort the base by dnloads
  91.     for(i=2;i<=rnum+1;i++) {                // For 'rnum' records
  92.         if(i>BaseCount ()) break;           // Abort if out of records
  93.         didx[i-2]=BaseIdx (i);              // Save the record number
  94.     }
  95.  
  96.     BaseSort (IDX_DEFAULT);                 // Return to default index
  97.  
  98.     printf ("\nScanning for totals -    1");
  99.  
  100.     for(i=2;i<=BaseCount ();i++) {          // Ignore first sysop record
  101.         if (!BaseRead (i)) {
  102.             printf ("\nERROR reading user file\n");
  103.             return 0;
  104.         }
  105.  
  106.         ctotal=ctotal+USRcalls;             // Update the calls total
  107.         utotal=utotal+USRupld;              // Update the uploads total
  108.         dtotal=dtotal+USRdnld;              // Update the dnloads total
  109.  
  110.         if (!(i%50)) printf("%c%c%c%c%4d",8,8,8,8,i);
  111.     }
  112.  
  113.     printf("%c%c%c%c%4d records\n",8,8,8,8,i-1);    // End notify
  114.     return 1;
  115. }
  116.  
  117. readerror ()                                // Report a user base read problem
  118. {
  119.     printf ("\nERROR reading user file\n");
  120.     fclose (fp); return;
  121. }
  122.  
  123. writereport ()                              // Write the .BBS report file
  124. {
  125.     int i;
  126.     char colourhead[5], colourhund[5], colourboxb[5], colourdata[5];
  127.     char colouropt1[5], colouropt2[5], colouropt3[5], colourlabl[5];
  128.     char *head=" - TOP USER REPORT - ";
  129.     char *line="                     ──────────────────────────────────────\n";
  130.     char *b1 =   "┌─────────────────────────┬─────────────";
  131.     char *b2 =   "────────────┬─────────────────────────┐\n";
  132.     char *c1 =   "├─────────────────────────┼─────────────";
  133.     char *c2 =   "────────────┼─────────────────────────┤\n";
  134.     char *d1 =   "└─────────────────────────┴─────────────";
  135.     char *d2 =   "────────────┴─────────────────────────┘\n";
  136.  
  137.     fp=fopen (rfile,"wb");                  // Open report file
  138.     if (fp==NULL) return;
  139.  
  140.     printf ("Writing report file \"%s\" ",rfile);
  141.  
  142.     // The Avt() function returns a pointer to a static character array
  143.     // containing the requested avatar characters. The following strcpy's
  144.     // save the requested strings for later use. This IS specifically
  145.     // required to allow more than one colour sequence as an (f)printf
  146.     // parameter. The unseen trap that this avoids, is that all function
  147.     // call parameter data is interpreted at _function call_ time. The
  148.     // result of multiple avt() references in a (f)printf parameter list
  149.     // is that the data from the _last_ avt() call would be used for all
  150.     // references <grumble>.
  151.  
  152.     // Get avatar colour strings
  153.     strcpy (colourhead,Avt (COLOURHEAD)); strcpy (colourhund,Avt (COLOURHUND));
  154.     strcpy (colourboxb,Avt (COLOURBOXB)); strcpy (colourdata,Avt (COLOURDATA));
  155.     strcpy (colouropt1,Avt (COLOUROPT1)); strcpy (colouropt2,Avt (COLOUROPT2));
  156.     strcpy (colouropt3,Avt (COLOUROPT3));
  157.     strcpy (colourlabl,Avt (COLOURLABL,COLOURLABB));
  158.  
  159.     // Output CLS, MoreOff, heading and underline
  160.     fputc (MCLS,fp); fputc (MMOREOFF,fp);
  161.     fprintf (fp,"%s                     MUL v%s%s%s\n",
  162.         colourhead,VERSN,head,DateToStr (SysDate ()));
  163.     fprintf (fp,"%s%s",colourhund,line);
  164.  
  165.     fprintf (fp,"%s%s%s",colourboxb,b1,b2); // Output box top
  166.  
  167.     // Output box heading
  168.     fprintf (fp,"│%s TOP CALLER      (Calls) %s",colourlabl,colourboxb);
  169.     fprintf (fp,"│%s TOP UPLOADER       (Kb) %s",colourlabl,colourboxb);
  170.     fprintf (fp,"│%s TOP DOWNLOADER     (Kb) %s│",colourlabl,colourboxb);
  171.  
  172.     fprintf(fp,"\n%s%s",c1,c2);             // Output box divider
  173.  
  174.     // Output first data line
  175.     fprintf (fp,"│ %s",colouropt1);
  176.     if (cidx[0]) {
  177.         if (!BaseRead (cidx[0])) { readerror(); return; } // Find record
  178.         fprintf (fp,"%-17s %5lu %s│ %s",USRname,USRcalls,colourboxb,colouropt2);
  179.     }
  180.     else fprintf (fp,"                        %s│ %s",colourboxb,colouropt2);
  181.  
  182.     if (uidx[0]) {
  183.         if (!BaseRead (uidx[0])) { readerror(); return; } // Find record
  184.         fprintf (fp,"%-17s %5lu %s│ %s",USRname,USRupld,colourboxb,colouropt3);
  185.     }
  186.     else fprintf (fp,"                        %s│ %s",colourboxb,colouropt3);
  187.  
  188.     if (didx[0]) {
  189.         if (!BaseRead (didx[0])) { readerror(); return; } // Find record
  190.         fprintf (fp,"%-16s %6lu %s│\n",USRname,USRdnld,colourboxb);
  191.     }
  192.     else fprintf (fp,"                        %s│\n",colourboxb);
  193.  
  194.     // Output the remaining data
  195.     for (i=1;i<rnum;i++) {
  196.         fprintf (fp,"│ %s",colourdata);
  197.         if (cidx[i]) {
  198.             if (!BaseRead (cidx[i])) { readerror(); return; } // Find record
  199.             fprintf (fp,"%-17s %5lu %s│ %s",
  200.                USRname,USRcalls,colourboxb,colourdata);
  201.         }
  202.         else fprintf (fp,"                        %s│ %s",
  203.             colourboxb,colourdata);
  204.  
  205.         if (uidx[i]) {
  206.             if (!BaseRead (uidx[i])) { readerror(); return; } // Find record
  207.             fprintf (fp,"%-17s %5lu %s│ %s",
  208.                 USRname,USRupld,colourboxb,colourdata);
  209.         }
  210.         else fprintf (fp,"                        %s│ %s",
  211.             colourboxb,colourdata);
  212.  
  213.         if (didx[i]) {
  214.             if (!BaseRead (didx[i])) { readerror(); return; } // Find record
  215.             fprintf (fp,"%-16s %6lu %s│\n",USRname,USRdnld,colourboxb);
  216.         }
  217.         else fprintf (fp,"                        %s│\n",colourboxb);
  218.     }
  219.  
  220.     fprintf(fp,"%s%s",c1,c2);               // Output box divider
  221.  
  222.     // Totals
  223.     fprintf (fp,"│ %s",colourhead);
  224.     fprintf (fp,"Total Calls   %s%9lu %s│ %s",
  225.         colouropt1,ctotal,colourboxb,colourhead);
  226.     fprintf (fp,"Total Uploads %s%9lu %s│ %s",
  227.         colouropt2,utotal,colourboxb,colourhead);
  228.     fprintf (fp,"Total Dnloads %s%9lu %s│\n",
  229.         colouropt3,dtotal,colourboxb);
  230.  
  231.     // Output lower box border
  232.     fprintf (fp,"%s%s%s",colourboxb,d1,d2);
  233.  
  234.     // Press Enter prompt and CLS
  235.     fprintf (fp,"%s%c",Avt (WHITE,BLACK),MENTER);
  236.     fprintf (fp,"%s%c",Avt (LGREY,BLACK),MCLS);
  237.  
  238.     fclose (fp);                            // Close report file
  239.     putch ('\n');                           // End notify
  240. }
  241.  
  242. // Byebye
  243. saybibi ()
  244. {                             
  245.     puts ("\nTopUser done!\n");
  246. }
  247.  
  248. // End of script
  249.  
  250.